/* eslint-disable @typescript-eslint/no-unused-vars */
import { useFormModal } from '@/hooks/useFormModal';
import { storage } from '@/utils/Storage';
import { getFormSchema } from './form-schema';

export const columns: TableColumn[] = [
  {
    title: '',
    dataIndex: 'id',
    hidden: true
  },
  {
    title: '用户ID',
    width: 200,
    dataIndex: 'userid'
  },
  {
    title: '',
    hidden: true,
    dataIndex: 'roleIds'
  },
  {
    title: '登录名称',
    width: 100,
    dataIndex: 'loginname'
  },
  {
    title: '用户名称',
    width: 100,
    dataIndex: 'username'
  },
  {
    title: '用户组名称',
    width: 100,
    dataIndex: 'groupname'
  },
  {
    title: '有效状态',
    width: 100,
    dataIndex: 'useful',
    slots: {
      customRender: 'useful'
    },
    slotsType: 'format',
    slotsFunc: (val) => (val == 1 ? '有效' : '无效')
    // slotsType: 'component',
    // slotsFunc: (val, refreshTableData) =>
    //   createVNode(Switch, {
    //     'checked-children': '有效',
    //     'un-checked-children': '无效',
    //     checked: val.useful == 1,
    //     onChange: async (e) => {
    //       const params = {
    //         loginId: val.loginId,
    //         isEnable: e ? 1 : 0,
    //         operatorId: storage.get(ACCESS_TOKEN),
    //       };
    //       await patchSysUserStatus(params);
    //       refreshTableData();
    //     },
    //   }),
  },
  {
    title: '性别',
    width: 100,
    dataIndex: 'sex'
  },
  {
    title: '电话',
    width: 150,
    dataIndex: 'phone'
  },
  {
    title: '邮箱',
    width: 200,
    dataIndex: 'email'
  },
  {
    title: '角色',
    width: 150,
    dataIndex: 'roleNames',
    slots: {
      customRender: 'roleNames'
    },
    slotsType: 'format',
    slotsFunc: (roles) => roles.join(', ')
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 65,
    slots: {
      customRender: 'action'
    },
    actions: [
      {
        type: 'button', // 控制类型，默认为a,可选： select | button | text
        text: '编辑',
        func: ({ record }, refreshTableData) =>
          useFormModal({
            title: '编辑用户',
            fields: record,
            width: '960px',
            formSchema: getFormSchema(),
            handleOk: async (modelRef, state) => {
              const params = {
                phone: modelRef.phone,
                userid: record.userid,
                operatorName: storage.get('username'),
                roleIds: modelRef.roleIds
              };
              return;
            }
          })
      }
    ]
  }
];
